<?php
/** 
 * $Source: /cvsroot/pn-commerce/pn-commerce/pntemplates/plugins/function.pncGetOrdersByUser.php,v $
 * $Author: pcornelissen $
 * $Revision: 1.4 $
 * $Date: 2003/12/08 12:09:47 $
 *
 * Type: Function
 *
 * returns an array with all orders for the given username. Structure is inherited by getOrder.
 * @param  user : (optional) the username for the query, default= actual user
 * @param  assign : (optional) the name for the variable, default = orders
 */
function smarty_function_pncGetOrdersByUser($params, &$smarty)
{
    $pnUser=pnUserGetVar('uname');
    if(!$params['user'])$params['user']=$pnUser;
    if (!pnSecAuthAction( 0, "pncommerce::order", $params['user']."::", ACCESS_ADMIN )&&($params['user']!=$pnUser) )
    {
        return;
    }
    
    extract($params);

    if( !pnModLoad( 'pncommerce', 'user' ) )
    {
        $smarty->trigger_error( "pncGetOrdersByUser: cannot load pnuser", E_USER_ERROR );
        return false;
    }

    if ( !pnModAPILoad( 'pncommerce', 'user' ) )
    {
        $smarty->trigger_error( "pncGetOrdersByUser: cannot load pnuserapi", E_USER_ERROR );
        return false;
    }

    if( !$assign )
    {
        $assign = 'Orders';
    }

    $orders = pnModAPIFunc( 'pncommerce', 'user', 'getOrdersByUser',
                           array( 'user' => $user ) );
    
    $smarty->assign( $assign, $orders );
	
}
?>
